#include "uart.h"

struct usart_regs
{
    unsigned USART_SR;
    unsigned USART_DR;
    unsigned USART_BRR;
    unsigned USART_CR1;
    unsigned USART_CR2;
    unsigned USART_CR3;
    unsigned USART_GTPR;
};

#define USART1 (*(volatile struct usart_regs *)0x40013800)

void uart_init(void)
{
    USART1.USART_BRR = 0x10; // div([15:4]+[3:0]/16)=fck/baud/16
    USART1.USART_CR1 = 0b0010000000001000; // UE = 1 (USART enable), M = 0 (8 Data bits), TE = 1 (transmitter enable)
}

void uart_putchar(char c)
{
    USART1.USART_DR = c;
    while (!(USART1.USART_SR & 0b0001000000));
}
